from .bootstrap import get_bootstrap_cfg
from .schema_load import load_schemas
from .schema_proc import process_schemas
from .config_load import load_configs
from .config_proc import process_configs

_running_cfg = None

# NOTE: This will raise exception if there is unrecoverable error (e.g.,
# cannot find schemas etc.). This should be acceptable since nothing can
# be expected to work in such cases anyway.
def get_running_cfg(force_reload=False):
    global _running_cfg
    if force_reload or (_running_cfg is None):
        bootstrap_cfg = get_bootstrap_cfg()
        schema_objs = load_schemas(bootstrap_cfg)
        schema_tree_obj = process_schemas(schema_objs)
        config_objs = load_configs(bootstrap_cfg)
        _running_cfg = process_configs(schema_tree_obj, config_objs)

    return _running_cfg

